package org.prail.threads;

import org.prail.net.core.Search;
import org.prail.ui.Mp3Frame;
import org.prail.ui.ResultsTable;
import org.prail.wrappers.SearchResult;

public class SearchThread extends Thread {
	private String find = null;

	/**
	 * Sets the song to search for
	 * 
	 * @param song
	 *            to search for
	 */
	public void searchFor(final String find) {
		this.find = find;
	}

	/**
	 * Searches for song and add its it too the table
	 */
	@Override
	public void run() {
		ResultsTable.get().empty();
		Mp3Frame.setSearch(false);
		final SearchResult[] results = Search.search(find);
		for (final SearchResult result : results) {
			try {
				ResultsTable.get().add(result);
			} catch (Exception e) {

			}
		}
		Mp3Frame.setSearch(true);
	}

	/**
	 * Gets instance of this thread or creates one
	 * 
	 * @return instance of this thread
	 */
	public static SearchThread get() {
		return new SearchThread();
	}

}
